package cn.doitedu.test

public class HelloWorldGroovy {

    public static void main(String[] args) {


        String code = "package cn.doitedu.test;\n" +
                "\n" +
                "public class ModelX_Calculator implements GroovyCalculator{\n" +
                "\n" +
                "\n" +
                "    @Override\n" +
                "    public void init() {\n" +
                "        System.out.println(\"我被init了\");\n" +
                "    }\n" +
                "\n" +
                "    @Override\n" +
                "    public void calculate(String name) {\n" +
                "        System.out.println(\"我被calculate了\");\n" +
                "\n" +
                "    }\n" +
                "}\n";

        // 编译、加载
        GroovyClassLoader groovyClassLoader = new GroovyClassLoader()
        Class clazz = groovyClassLoader.parseClass(code)

        // 反射
        GroovyCalculator ruleCalculator = (GroovyCalculator) clazz.newInstance()

        ruleCalculator.init();

        ruleCalculator.calculate("深似海")





    }

}
